#{extends '/template/main.html' /}
<!-- Removing search and results count filter -->
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">全部订单</h3>
    </div>
    <div class="panel-body">
        <form method="get" id="searchForm" action="/BS0017/admin/order/index/${pageNumber}">
            <div style="margin-bottom: 20px;width:160px;float: left;">
                <input type="text" name="orderNumber" id="orderNumber" class="form-control" style="width:150px" placeholder="订单编号" value="${orderNumber}">
            </div>
            <div style="margin-bottom: 20px;width:120px;float: left;margin-right: 10px;">
                <input type="text" class="form-control datepicker" data-format="yyyy-mm-dd" name="startTime" style="width: 120px" placeholder="开始时间" value="${startTime}">
            </div>
            <div style="margin-bottom: 20px;width:120px;float: left;margin-right: 10px;">
                <input type="text" class="form-control datepicker" data-format="yyyy-mm-dd" name="endTime" style="width: 120px" placeholder="结束时间" value="${endTime}">
            </div>
            <div style="margin-bottom: 20px;width:120px;float: left;margin-right: 10px;">
                <select name="status" class="form-control" style="width: 120px">
                    <option value="" ${status == null ? 'selected' : ''}>全部支付状态</option>
                    <option value="UNPAID" ${status.toString() == 'UNPAID' ? 'selected' : ''}>未付款</option>
                    <option value="PAID" ${status.toString() == 'PAID' ? 'selected' : ''}>已付款</option>
                    <option value="CANCELED" ${status.toString() == 'CANCELED' ? 'selected' : ''}>交易取消</option>
                </select>
            </div>
            <div style="margin-bottom: 20px;width:120px;float: left;margin-right: 10px;">
                <select name="payType" class="form-control" style="width: 120px">
                    <option value="" ${payType == null ? 'selected' : ''}>全部支付方式</option>
                    *{<option value="WEIXIN" ${payType.toString() == 'WEIXIN' ? 'selected' : ''}>微信原生支付</option>}*
                    <option value="WEIXIN_PUB" ${payType.toString() == 'WEIXIN_PUB' ? 'selected' : ''}>微信公众号支付</option>
                    <option value="WEIXIN_PUB_QR" ${payType.toString() == 'WEIXIN_PUB_QR' ? 'selected' : ''}>微信扫码支付</option>
                    *{<option value="ECOUPON" ${payType.toString() == 'ECOUPON' ? 'selected' : ''}>优惠券</option>}*
                    *{<option value="INTEGRAL" ${payType.toString() == 'INTEGRAL' ? 'selected' : ''}>积分</option>}*
                    *{<option value="ECASH" ${payType.toString() == 'ECASH' ? 'selected' : ''}>代金券</option>}*
                    <!--<option value="ALI_PC_DIRECT" ${payType.toString() == 'ALI_PC_DIRECT' ? 'selected' : ''}>支付宝</option>-->
                    <option value="CASH" ${payType.toString() == 'CASH' ? 'selected' : ''}>现金</option>
                    <option value="ALI_QR" ${payType.toString() == 'ALI_QR' ? 'selected' : ''}>支付宝</option>
                    <option value="ALI_QR" ${payType.toString() == 'GS_ALI' ? 'selected' : ''}>公司支付宝</option>
                    <option value="ALI_QR" ${payType.toString() == 'GS_WEIXIN' ? 'selected' : ''}>公司微信</option>
                    *{<option value="DEDUCTIBLE_COUPON" ${payType.toString() == 'DEDUCTIBLE_COUPON' ? 'selected' : ''}>抵扣券抵扣</option>}*
                </select>
            </div>
            <div style="margin-bottom: 20px;width:120px;float: left;margin-right: 10px;">
                <input type="hidden" name="frozenGoodsType" id="frozenGoodsType" value="${frozenGoodsType}">
                <select name="orderType" class="form-control" ${frozenGoodsType ? 'disabled' : ''}   style="width: 120px">
                    <option value="" ${orderType == null ? 'selected' : ''}>全部订单来源</option>
                    *{<option value="COACH" ${orderType.toString() == 'COACH' ? 'selected' : ''}>教练</option>}*
                    <option value="CURRICULUM" ${orderType.toString() == 'CURRICULUM' ? 'selected' : ''}>课程</option>
                    *{<option value="FIELD" ${orderType.toString() == 'FIELD' ? 'selected' : ''}>场地</option>}*
                    <option value="SPORTS_ROOMS" ${orderType.toString() == 'SPORTS_ROOMS' ? 'selected' : ''}>竞技包房</option>
                    <option value="RECHARGE" ${orderType.toString() == 'RECHARGE' ? 'selected' : ''}>会员卡充值</option>
                    <option value="PRODUCT" ${orderType.toString() == 'PRODUCT' ? 'selected' : ''}>产品</option>
                    <option value="THIRDPARTY" ${orderType.toString() == 'THIRDPARTY' ? 'selected' : ''}>第三方平台</option>
                    <option value="NO_PRODUCT" ${orderType.toString() == 'NO_PRODUCT' ? 'selected' : ''}>水吧无产品订单</option>
                    <option value="FEIYANGXINGQIU" ${orderType.toString() == 'FEIYANGXINGQIU' ? 'selected' : ''}>飞氧星球</option>
                </select>
            </div>
            <div style="margin-bottom: 20px;width:120px;float: left;margin-right: 10px;">
                <select name="supplierId" class="form-control" style="width: 120px">
                    <option value="" ${supplierId == null ? 'selected' : ''}>全部供应商</option>
                    #{list supplierList ,as:'supplier'}
                        <option value="${supplier.id}" ${supplierId == supplier.id ? 'selected' : ''}>${supplier.name}</option>
                    #{/list}

                </select>
            </div>

        </form>
        <button class="btn btn-turquoise" id="searchBtn">开始检索</button>
        <button class="btn btn-turquoise" onclick="exportExcel()">导出</button>

        <table class="table table-bordered table-striped" id="example-2">
            <thead>
            <tr>
                *{<th class="no-sorting">}*
                    *{<input type="checkbox" class="cbr">}*
                *{</th>}*
                <th>订单编号</th>
                <th>下单人</th>
                <th>下单时间</th>
                <th>类型</th>
                <th>金额(元)</th>
                <th>支付状态</th>
                *{<th>确认支付</th>}*
                <th>折扣</th>
                <th>发票</th>
                <th>订单创建人</th>
                <th>供应商</th>
                <th>操作</th>
            </tr>
            </thead>

            <tbody class="middle-align">
            #{paginate.list items:resultPage , as :'order'}
            <tr>
                *{<td>}*
                    *{<input type="checkbox" class="cbr">}*
                *{</td>}*
                <td>${order?.orderNumber}</td>
                <td>${order?.webUser?.nickName}</td>
                <td>${order?.createdAt?.format('MM-dd HH:mm')}</td>
                <td>&{'GoodsType.' + order?.goodsType}</td>
                <td>${order?.amount?.format('#.##')}</td>
                <td>&{'OrderStatus.' + order?.status}</td>
                *{<td>${order?.confirmStatus == null ? '未确认':'已确认'}</td>}*
                <td>${order?.discountRate}</td>
                <td>${order?.invoiceStatus == true ? '已开':'未开'}</td>
                <td>${order?.creator?.name}</td>
                <td>${order?.supplier?.name}</td>
                <td>
                    <a href="/BS0023/admin/order/detail/${order?.id}/${pageNumber}" class="btn btn-secondary btn-sm btn-icon icon-left">
                        查看
                    </a>
                    <a href="#" onclick="deletedComfim(${order?.id});" class="btn btn-danger btn-sm btn-icon icon-left">
                        删除
                    </a>
                    <a href="#" onclick="invoiceConfirm(${order?.id})" class="btn btn-info btn-sm btn-icon icon-left">
                        发票
                    </a>
                    <a href="/BS0023/admin/order/print/${order?.id}/${pageNumber}" target="_blank"  class="btn btn-info btn-sm btn-icon icon-left">
                        打印
                    </a>

                </td>
            </tr>
            #{/paginate.list}
            </tbody>
        </table>
        <div id="layerPage" class="col-xs-12"></div>
    </div>
</div>



<!-- Imported styles on this page -->
<link rel="stylesheet" href="/public/js/datatables/dataTables.bootstrap.css">

<script src="/public/js/datatables/js/jquery.dataTables.min.js"></script>


<!-- Imported scripts on this page -->
<script src="/public/js/datatables/dataTables.bootstrap.js"></script>
<script src="/public/js/datatables/yadcf/jquery.dataTables.yadcf.js"></script>
<script src="/public/js/datatables/tabletools/dataTables.tableTools.min.js"></script>

<script type="text/javascript" src="/public/laypage/laypage.js"></script>
<script type="text/javascript">
    var orderType = '${orderType}';
    var frozenGoodsType = '${frozenGoodsType}';
    var pageNumber = '${pageNumber}';
    $(document).ready(function(){
        // 提示
        var msg = '${flash.get("msg")}';
        if(msg) {
            saveSuccess(msg);
        }

        // 分页
        laypage({
            cont: $('#layerPage'), //容器。值支持id名、原生dom对象，jquery对象,
            pages: '${resultPage?.pageCount}', //总页数
            skin: 'yahei',
            curr:'${pageNumber}',
            jump: function(e, first){ //触发分页后的回调
                if(!first){ //一定要加此判断，否则初始时会无限刷新
                    $('#pageNumber').val(e.curr);
                    $("#searchForm").attr("action", "/BS0017/admin/order/index/"+e.curr);
                    $('#searchForm').submit();
                }
            }
        });
        $(document).on("click", "#searchBtn", function(){
            $("#searchForm").attr("action", "/BS0017/admin/order/index/1");
            $('#searchForm').submit();
        })
    });


    //点击确认删除 之后执行的方法
    function sureDeleted() {

        //获取删除的id
        var id = $('#deleteId').val();
        *{document.location.href='/BS0017/admin/order/delete/'+id+'/${pageNumber}';}*
        var remark = $('#idRemark').val();
        if(remark == null || remark.length == 0){
            layer.msg('请填写备注!');
            return;
        }
        $('#deleteModal').modal('hide');
        $.getJSON('/BS0017/admin/order/delete',{id:id  , remark:remark},function (data) {
            if(data.success){
                window.location.href = "/BS0017/admin/order/index/"+pageNumber;
            }else {

                layer.msg(data.msg);
            }
        })
    }

    //导出
    function exportExcel() {
        var url = '/BS0017/admin/order/exportExcel';
        if(frozenGoodsType != null && frozenGoodsType != '')
            url += '/' + orderType + '/' + frozenGoodsType;
        $("#searchForm").attr("action", url);
        $('#searchForm').submit();
    }

    function invoiceConfirm(id) {
        $('#id_order_invoice_id').val(id);
        $('#id_invoice_code').val('');
        $("#idInvoiceModel").modal('show');
    }
    function saveInvoiceCode() {
        var orderId = $('#id_order_invoice_id').val();
        var invoiceCode = $('#id_invoice_code').val();
        if(invoiceCode == null || invoiceCode == ''){
            layer.msg("请填写发票编号!");
            return ;
        }

        $.getJSON('/BS0017/admin/order/confirmInvoice',{orderId: orderId , invoiceCode: invoiceCode},function (data) {
            if(data.success){
                window.location.href = "/BS0017/admin/order/index";
            }else {
                $("#idInvoiceModel").modal('hide');
                layer.msg(data.msg);
            }

        })

    }

</script>


